package system

import (
	"github.com/gin-gonic/gin"

	"go-papers/models"
	"go-papers/tools"
	"go-papers/tools/app"
)

func GetInfo(c *gin.Context) {

	var roles = make([]string, 1)
	roles[0] = tools.GetRoleName(c)

	var permissions = make([]string, 1)
	permissions[0] = "*:*:*"
	RoleMenu := models.RoleMenu{}
	RoleMenu.RoleId = tools.GetRoleId(c)

	var mp = make(map[string]interface{})
	mp["roles"] = roles
	if tools.GetRoleName(c) == "admin" || tools.GetRoleName(c) == "系统管理员" {
		mp["permissions"] = permissions
	} else {
		list, _ := RoleMenu.GetPermis()
		mp["permissions"] = list
	}

	sysuser := models.SysUser{}
	sysuser.UserId = tools.GetUserId(c)
	user, err := sysuser.Get()
	if err != nil {
		app.ApiResp(c, -1, "数据解析失败："+err.Error(), nil)
		return
	}

	mp["avatar"] = "https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3140403455,2984550794&fm=26&gp=0.jpg"
	if user.Avatar != "" {
		mp["avatar"] = user.Avatar
	}
	mp["introduction"] = " 我的簽名我做主"
	if user.Remark != "" {
		mp["introduction"] = user.Remark
	}
	mp["name"] = user.NickName
	mp["username"] = user.Username
	mp["nick_name"] = user.NickName
	mp["organ_id"] = user.OrganId
	mp["organ_name"] = user.OrganName
	mp["userType"] = tools.GetUserType(c)
	if user.DeptId > 0 {
		var deptM models.Dept
		deptM.DeptId = user.DeptId
		dept, _ := deptM.Get()
		mp["dept_info"] = dept
		mp["dept_name"] = dept.DeptName
	} else {
		mp["dept_name"] = ""
		mp["dept_info"] = nil
	}

	if user.PostId > 0 {
		var postM models.Post
		postM.PostId = user.PostId
		post, _ := postM.Get()

		mp["post_name"] = post.PostName
		mp["post_info"] = post
	} else {
		mp["post_name"] = ""
		mp["post_info"] = nil
	}

	app.CommonResp(c, 0, "成功", mp)
}
